package com.jcfk.eam.controller.bd;

import cn.hutool.core.util.StrUtil;
import com.jcfk.common.business.enums.AvailableStatus;
import com.jcfk.common.business.log.annotation.RequestLogHeader;
import com.jcfk.common.business.utils.DataBindHelper;
import com.jcfk.common.web.domain.DataPage;
import com.jcfk.common.web.domain.ReqPageParam;
import com.jcfk.common.web.domain.RetPage;
import com.jcfk.common.web.domain.RetResult;

import com.jcfk.eam.domain.dto.base.EamInspectionRouteDTO;
import com.jcfk.eam.domain.dto.base.EamInspectionRouteLocationDTO;
import com.jcfk.eam.domain.query.base.EamInspectionRouteQuery;
import com.jcfk.eam.service.base.EamInspectionRouteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


import java.util.List;

/**
 * 巡检路线
 *
 * @author libinghai
 * @email 35738025@gqq.com
 * @date 2024-08-27
 */
@Api(tags = {"巡检路线管理"})
@RestController
@RequestMapping("eamInspectionRoute")
public class EamInspectionRouteController {
    @Autowired
    private EamInspectionRouteService eamInspectionRouteService;

    /**
     * 分页列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "ReqPageParam<EamInspectionRouteQuery>", name = "requestParam", value = "", required = true)
    })
    @ApiOperation("分页查询巡检路线")
    @PostMapping("/queryByPage")
    public RetPage<EamInspectionRouteDTO> queryByPage(@RequestBody ReqPageParam<EamInspectionRouteQuery> requestParam) {
        DataPage<EamInspectionRouteDTO> page = new DataPage<EamInspectionRouteDTO>((long) requestParam.getCurrent(),
                (long) requestParam.getSize(),
                requestParam.getSort().getOrderItem(),
                EamInspectionRouteDTO.class);
        page = eamInspectionRouteService.queryByPage(page, requestParam.getData());

        return new RetPage<>(page);
    }


    /**
     * 获取信息列表
     *
     * @param query
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "EamInspectionRouteQuery", name = "query", value = "", required = true)
    })
    @ApiOperation(value = "获取巡检路线列表", notes = "获取巡检路线列表", httpMethod = "POST")
    @PostMapping("getDetails")
    public RetResult<List<EamInspectionRouteLocationDTO>> getDetails(@RequestBody EamInspectionRouteQuery query) {

        List<EamInspectionRouteLocationDTO> list = eamInspectionRouteService.getDetails(query);

        return RetResult.ok(list);
    }

    /**
     * 获取信息列表
     *
     * @param query
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "EamInspectionRouteQuery", name = "query", value = "", required = true)
    })
    @ApiOperation(value = "获取巡检路线列表", notes = "获取巡检路线列表", httpMethod = "POST")
    @PostMapping("getList")
    public RetResult<List<EamInspectionRouteDTO>> getList(@RequestBody EamInspectionRouteQuery query) {

        List<EamInspectionRouteDTO> list = eamInspectionRouteService.getList(query);

        return RetResult.ok(list);
    }


    /**
     * 巡检路线
     * 根据id 查询详情
     */
    @ApiOperation("查询巡检路线")
    @GetMapping("/get/{id}")
    public RetResult<EamInspectionRouteDTO> get(@PathVariable("id") String id) {
        EamInspectionRouteDTO item = eamInspectionRouteService.get(id);
        return RetResult.ok(item);
    }

    /**
     * 添加/更新管理巡检路线
     */
    @ApiOperation("保存巡检路线")
    @PostMapping("/save")
    @RequestLogHeader(modular = "巡检路线管理", businessType = "保存")
    public RetResult<?> save(@RequestBody @Valid EamInspectionRouteDTO eamInspectionRoute) {
        // 数据校验
        RetResult ret = eamInspectionRouteService.isValid(eamInspectionRoute);
        if (!ret.getCode().equals(RetResult.SUCCESS)) {
            return ret;
        }

        if (StrUtil.isEmpty(eamInspectionRoute.getId())) {
            // 新增
            eamInspectionRouteService.insert(eamInspectionRoute);
        } else {
            // 更新
            eamInspectionRouteService.update(eamInspectionRoute);
        }
        return RetResult.ok();

    }


    /**
     * 批量删除巡检路线
     */
    @ApiOperation("批量删除巡检路线")
    @PostMapping("/delete")
    @RequestLogHeader(modular = "巡检路线管理", businessType = "批量删除")
    public RetResult<?> delete(@RequestBody EamInspectionRouteDTO eamInspectionRoute) {
        return RetResult.ok(eamInspectionRouteService.logicDeleteList(eamInspectionRoute));
    }


    /**
     * 删除巡检路线
     */
    @ApiOperation("删除巡检路线")
    @PostMapping("/deleteItem/{id}")
    @RequestLogHeader(modular = "巡检路线管理", businessType = "删除")
    public RetResult<?> deleteItem(@PathVariable("id") String id) {
        eamInspectionRouteService.deleteitem(id);
        return RetResult.ok();
    }
}
